<template>
  <div>
    <h2>登录</h2>
    <hr />
    <table>
      <tr>
        <td align="right">账号:</td>
        <td><input type="text" v-model="state.Name" /></td>
      </tr>
      <tr>
        <td align="right">密码:</td>
        <td><input type="password" v-model="state.Pwd" /></td>
      </tr>
      <tr>
        <td align="right"></td>
        <td><input type="button" value="登录" @click="login" /></td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import{reactive,toRefs,onMounted} from 'vue';
import{useRouter,useRoute} from 'vue-router';
import axios from 'axios';

const router = useRouter();
const route = useRoute();
let data:any = reactive({
  state:{
    Name:'',
  Pwd:''
  }

})
let {state} = toRefs(data);

function login(){
  let obj={
    Name:state.value.Name,
    Pwd:state.value.Pwd
  }
  axios({
    url:'https://localhost:7105/api/Member/Login',
    method:'post',
    params:obj
  })
  .then((res)=>{
    console.log(res);
    if(res.data.data==-1){
    alert("账号不存在")
    return;
  }else if(res.data.data>0){
    alert("登录成功");

    router.push('/Add');
    }else{
      alert('登录失败');
    }
  })
  .catch((err)=>{
    console.log(err);
  })
}

</script>

<style scoped></style>
